package hot;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/3/8 17:14
 * @Version 1.0
 */
public class Hot20isValid {
    public boolean isValid(String s) {
        Deque<Character> stack = new LinkedList<>();
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)==')' && !stack.isEmpty() && stack.peek()=='('){
                stack.pop();
            }else {
                if(s.charAt(i)==']' && !stack.isEmpty() && stack.peek()=='['){
                    stack.pop();
                }else {
                    if(s.charAt(i)=='}' && !stack.isEmpty() && stack.peek()=='{'){
                        stack.pop();
                    }else {
                        stack.push(s.charAt(i));
                    }
                }
            }
        }
        return stack.isEmpty();
    }
}
